<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../header.jsp"%>

<script type="text/javascript" src="<%=ctx%>/js/jquery.bootstrap-carousel.js"></script>
<script type="text/javascript" src="<%=ctx%>/js/jquery.bootstrap-transition.js"></script>

<script type="text/javascript">
var photoLoaded = false;
var prospectLoaded = false;

function saveSucceedCallback(data) {
	unblock("#detailForm");
	if (!data.succeed) {
		$.notice("保存失败，原因为：\n"+data.message);
		return;
	}
	$.info("保存成功！");
	//保存成功后更新页面数据。避免在web页面打开的情况下，用户在app上做了提交等（单据处理状态已变更）操作后，文本页面上的数据不更新
	loadSucceedCallback(data);
}

function loadPhotosByTask(){
	if(photoLoaded){
		return;
	}
	photoLoaded = true;
	
	var status = $("#taskStatus").data("code");
	if("completed" != status){
		$("#photoCarousel").hide();
		$("#photoNotExistsDiv").show();
		return;
	}
	
	$("#photoCarousel").show();
	$("#photoNotExistsDiv").hide();
	
	var taskId = $("#taskId").val();
	$.ajax({
		type: "GET",
		cache: false,
		url: "attachment/list.json?resourceId=" + taskId,
		dataType: "json",
		success: loadPhotosSucceedCallback,
		error:function(message){
			$.alert(message);
		}
	});
}

function loadProspectByTask(){
	if(prospectLoaded){
		return;
	}
	
	var taskId = $("#taskId").val();
	var prospectRecodId = $("#prospectRecodId").val();
	$.ajax({
		type: "GET",
		cache: false,
		url: "prospect/detail.json?id="+prospectRecodId+"&taskId=" + taskId,
		dataType: "json",
		success: loadProspectSucceedCallback,
		error:function(message){
			$.alert(message);
		}
	});
}

$(document).ready(function() {
//	$("#tabs").tab("show");
	$('a[data-toggle="tab"]').on('shown', function (e) {
		var actived = $(e.target).attr("href");
		if(actived == "#prospectPanel"){
			loadProspectByTask();
		}else if(actived == "#photoPanel"){
			loadPhotosByTask();
		} else if (actived == "#mapPanel") {
			loadTaskMap();
		}
	});
});
</script>

<div class="left">
<div class="border bg">

<div class="page-header">
<h2>任务管理<small id="taskTitle"></small></h2>
<div class="cms_toolbar">
	<a href="javascript:;" onclick="goBack('dispatches.do')" class="btn"><i class="icon-list"></i>返回</a>
</div>
</div>


<div id="tabs">
<ul class="nav nav-tabs">
<li class="active"><a href="#detailPanel" data-toggle="tab">基本信息</a></li>
<li><a href="#prospectPanel" data-toggle="tab">项目情况</a></li>
<li><a href="#photoPanel" data-toggle="tab">现场照片<small id="photoIndex"></small></a></li>
<li><a href="#mapPanel" data-toggle="tab">现场地图</a></li>
</ul>

<div class="tab-content">
<div id="detailPanel" class="tab-pane fade in active">
	<%@ include file="edit.detail.jsp"%>
</div>

<div id="prospectPanel" class="tab-pane fade">
	<jsp:include page="edit.prospect.jsp"/>
</div>

<div id="photoPanel" class="tab-pane fade">
	<jsp:include page="detail.photo.jsp"/>
	<div class="well" id="photoNotExistsDiv">
		此任务未完成，尚未有现场照片！
	</div>
</div>

<div id="mapPanel" class="tab-pane fade">
	<jsp:include page="detail.map.jsp"/>
	<div class="well" id="resultNotExistsDiv">
		此任务未完成，尚未有现场地图！
	</div>
</div>

</div>
</div>
</div>
</div>


<%@ include file="../../footer.jsp"%>